from Object3D import *
from OpenGL.GL import *
from Texture import *

class Room(Object3D):

	def __init__(self):
		super(Room, self).__init__()
		self.width = 10.0
		self.height = 5.0
		self.depth = 10.0
		self.texture = Texture()
		self.floorTextureId = self.texture.loadTextures("piso.bmp")
		self.wallTextureId = self.texture.loadTextures("parede.bmp")

	def draw(self):
		halfW = self.width / 2.0
		halfD = self.depth / 2.0

		glPushMatrix()

		glTranslatef(*self.position.list())

		glEnable(GL_TEXTURE_2D)
		self.texture.bindTexture(self.floorTextureId)
		
		glMaterialfv(GL_FRONT, GL_AMBIENT, [0.7,0.1,0.1,1.0])
		glMaterialfv(GL_FRONT, GL_DIFFUSE, [0.8,0.1,0.1,1.0])
		glMaterialfv(GL_FRONT, GL_SPECULAR, [0.5,0.5,0.5,1.0])

		glBegin(GL_QUADS)
		#floor
		glNormal3f(0.0,1.0,0.0)
		glTexCoord2f(0.0, 0.0)
		glVertex3f(-halfW,0,-halfD)
		glTexCoord2f(1.0, 0.0)
		glVertex3f(-halfW,0,halfD)
		glTexCoord2f(1.0, 1.0)
		glVertex3f(halfW,0,halfD)
		glTexCoord2f(0.0, 1.0)
		glVertex3f(halfW,0,-halfD)
		glEnd()

		glDisable(GL_TEXTURE_2D)
		
		glMaterialfv(GL_FRONT, GL_AMBIENT, [0.1,0.1,0.1,1.0])
		glMaterialfv(GL_FRONT, GL_DIFFUSE, [0.65,0.65,0.65,1.0])
		glMaterialfv(GL_FRONT, GL_SPECULAR, [0.5,0.5,0.5,1.0])

		glEnable(GL_TEXTURE_2D)
		self.texture.bindTexture(self.wallTextureId)
		glBegin(GL_QUADS)
		#back wall
		glNormal3f(0.0,0.0,-1.0)
		glTexCoord2f(0.0, 0.0)
		glVertex3f(halfW,0,halfD)
		glTexCoord2f(1.0, 0.0)
		glVertex3f(-halfW,0,halfD)
		glTexCoord2f(1.0, 1.0)
		glVertex3f(-halfW,self.height,halfD)
		glTexCoord2f(0.0, 1.0)
		glVertex3f(halfW,self.height,halfD)
		glEnd()
		glDisable(GL_TEXTURE_2D)

		glEnable(GL_TEXTURE_2D)
		self.texture.bindTexture(self.wallTextureId)
		glBegin(GL_QUADS)
		#left wall
		glNormal3f(-1.0,0.0,0.0)
		glTexCoord2f(1.0, 0.0)
		glVertex3f(halfW,0,halfD)
		glTexCoord2f(1.0, 1.0)
		glVertex3f(halfW,self.height,halfD)
		glTexCoord2f(0.0, 1.0)
		glVertex3f(halfW,self.height,-halfD)
		glTexCoord2f(0.0, 0.0)
		glVertex3f(halfW,0,-halfD)
		glEnd()
		glDisable(GL_TEXTURE_2D)


		glEnable(GL_TEXTURE_2D)
		self.texture.bindTexture(self.wallTextureId)
		glBegin(GL_QUADS)
		#right wall
		glNormal3f(1.0,0.0,0.0)
		glTexCoord2f(1.0, 0.0)
		glVertex3f(-halfW,0,-halfD)
		glTexCoord2f(1.0, 1.0)
		glVertex3f(-halfW,self.height,-halfD)
		glTexCoord2f(0.0, 1.0)
		glVertex3f(-halfW,self.height,halfD)
		glTexCoord2f(0.0, 0.0)
		glVertex3f(-halfW,0,halfD)
		glEnd()
		glDisable(GL_TEXTURE_2D)

		#glEnd()

		glPopMatrix()